<?php
namespace Admin\Controller;
use Admin\Controller\AdminController;
class SysController extends AdminController {
    public function _initialize(){
        parent::_initialize();
    }
    //空操作
    public function _empty(){
        header("HTTP/1.0 404 Not Found");
        $this->display('Public:404');
    }
/**
     * 配置项主页
     */
    public function index(){
        $config=M('Config')->select();
        $this->assign('config',$config);
        $jifenrule=M('rob_rule');
        $content=$jifenrule->where("type=1")->find();
        $this->assign('content',$content);
        $this -> display();
    }
    /**
     * 修改配置项
     */
    public function editConfig(){
        $jifenrule=M('rob_rule');
        if($_POST['content_id']==''){
            $arr['id']='';
            $arr['title']='积分规则';
            $arr['content']=$_POST['content'];
            $arr['type']=1;
            $res=$jifenrule->add($arr);
            /* if($res){
                $this->success('积分规则修改成功');
            }else{
                $this->error('积分规则修改失败');
            } */
            
        }else{
            $arr2['content']=$_POST['content'];
            $res=$jifenrule->where(array('id'=>$_POST['content_id']))->save($arr2);
            /* if($res){
                $this->success('积分规则修改成功');
            }else{
                $this->error('积分规则修改失败');
            } */
        }
        
         if($_FILES["logo"]["tmp_name"]){
                $_POST['logo']=$this->upload($_FILES["logo"]);
                if (!$_POST['logo']){
                    $this->error('非法上传');
                }
         }
         if($_FILES["trademark"]["tmp_name"]){
            $_POST['trademark']=$this->upload($_FILES["trademark"]);
            if (!$_POST['trademark']){
                $this->error('非法上传');
            }
         }
        foreach ($_POST as $k=>$v){
            $rs[]=M('Config')->where(C("DB_PREFIX")."config.key='{$k}'")->setField('value',$v);
        }
        if($rs){
            $this->success('配置修改成功');
        }else{
            $this->error('配置修改失败');
        }
     }
    

}